package adapt;

public class VoltageAdapter implements Charge {
    Voltage voltage;

    public VoltageAdapter(Voltage voltage) {
        this.voltage = voltage;
    }

    @Override
    public int change220To5() {
        int dest = 0;
        if (null != this.voltage && this.voltage instanceof Voltage220V){
            Voltage220V voltage220V = (Voltage220V) voltage;
            int src = voltage220V.output220V();
            dest = src/44;
            System.out.println("电压由220V转换为5V成功");
        }else{
            System.out.println("电源电压不匹配，转换电压失败");
        }
        return dest;
    }
    @Override
    public int change440To10() {
        int dest = 0;
        if (null != this.voltage && this.voltage instanceof Voltage440V){
            Voltage440V voltage440V = (Voltage440V) voltage;
            int src = voltage440V.output440V();
            dest = src/44;
            System.out.println("电压由440V转换为10V成功");
        }else{
            System.out.println("电源电压不匹配，转换电压失败");
        }
        return dest;
    }
}
